package com.me.controller;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.me.entity.StudentPaper;
import com.me.service.ConfigService;
import com.me.service.StudentPaperService;

/**
 * 学生注册控制器
 * @author dong
 */
@Controller
public class RegisterController extends BaseController {
	/**
	 * 注入业务组件
	 */
	@Resource
	private StudentPaperService studentPaperService;
	@Resource
	private ConfigService configService;
	
	/**
	 * 进入注册页
	 */
	@RequestMapping("/index.do")
	public String toRegister(){
		return "register";
	}
	
	
	/**
	 * 注册操作
	 */
	@RequestMapping("/signIn.do")
	@ResponseBody
	public Map<String, Object> signIn(StudentPaper studentPaper){
		try {
			LOG.info("--------注册信息：" + studentPaper + "--------");
			// 设置默认平时成绩
			studentPaper.setRegularScore(configService.getRegularScore());
			// 执行入库操作
			studentPaperService.insert(studentPaper);
			// 注册成功
			return messageSuccess("注册成功，现在去登录？");
		} catch (Exception e) {
			e.printStackTrace();
			return messageFailure(e.getMessage(), "注册失败，请联系管理员！");
		}
	}
}
